home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Help With Pointers
- Date: 22 Feb 1996 12:09:10 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4giih6INNdr8@keats.ugrad.cs.ubc.ca>
- References: <4g67cj$6cv@hobbes.compusult.nf.ca>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4g67cj$6cv@hobbes.compusult.nf.ca>,
- Barry A. Ryan <bryan@public.compusult.nf.ca> wrote:
-
- >I'am actually trying to read SGI binary data with a PC. I've been told
- >that the SGI bytes ( not bits ) are rotated versus a PC. Any help
-
- Try using Sun XDR, which is standard for external data representation. If you
- write the data through XDR on one machine, you should be able to read it on the
- other machine. The XDR standard is not super robust, but on the other hand it
- is efficient and fairly compact. For float numbers, it uses IEEE format. If
- both machines use IEEE, XDR has no problem.
-
- #include <rpc/rpc.h>
-
- /*
- * write a float on standard output
- */
-
- int main()
-
- {
- XDR out; /* XDR stream structure */
- double mynum = 3.0;
-
- /* set up XDR stream to encode via standard output */
-
- xdrstdio_create(&out,stdout,XDR_ENCODE);
-
- /* encode ``mynum'' */
-
- xdr_double(&out,&mynum);
- }
-
-
- To decode from standard input, change the "stdout" to "stdin" and "XDR_ENCODE"
- to "XDR_DECODE". Everything else stays the same.
-
- XDR has way to decode to and from memory buffers, and record streams (via
- TCP/IP stream sockets).
-
- I use XDR extensively. In a recent project, a Windows programmer has built a
- client which communicates with my UNIX-based server. To compile the requestor
- protocol, he had to port XDR to the 16-bit environment, which went without a
- hitch. Though it's not part of the C standard, it is a mini standard in itself
- that is widely available on UNIX systems, is available in freely distributable
- form, and can be ported to 16-bit PC environments (which explains why PC-NFS
- works! XDR/RPC is the basis for all the Sun NFS/NIS software).
-
- XDR does the byte order conversions for you. There is a definition language for
- specifying complex structures, which automatically compile into C headers with
- structure declarations and recursive encoding/decoding C functions that you can
- compile and link with your project. Thus you can use the XDR language to make a
- structure "foo", and the "rpcgen" compiler will write a C function xdr_foo()
- for encoding/decoding that structure using the atomic primitives, along with C
- declarations.
- --
-
-